import { isNotEmpty } from './isNotEmpty';
// 非空规则校验
export const notEmptyRules = {
  // required: true,
  trigger: 'blur',
  validator(rules, value, callback) {
    if (value instanceof Array && (value.length === 0 || !value.every((item) => isNotEmpty(item))))
      callback(new Error(rules.message || ''));
    if (!isNotEmpty(value)) callback(new Error(rules.message || ''));
    callback();
  }
};
// 邮箱校验
export const emailRules = {
  trigger: 'blur',
  validator(rules, value, callback) {
    if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value)) return callback(new Error(rules.message || ' '));
    callback();
  }
};
